import dataApi from '@/api/data.api.js'
const state = {
  employeeList: [],
  departmentList: []
}

const getters = {
  employeeList: state => state.employeeList,
  departmentList: state => state.departmentList
}

const mutations = {
  SetEmployeeList (state, { employeeList }) {
    state.employeeList = employeeList
  },
  SetDepartmentList (state, { departmentList }) {
    state.departmentList = departmentList
  }
}

const actions = {
  getEmployeeList ({ commit }) {
    let employeeResult = dataApi.getEmployeeList()
    if (employeeResult.returncode === 0) {
      commit('SetEmployeeList', { employeeList: employeeResult.result })
    }
  },
  getDepartmentList ({ commit }) {
    let departmentResult = dataApi.getDepartmentList()
    if (departmentResult.returncode === 0) {
      commit('SetDepartmentList', { departmentList: departmentResult.result })
    }
  }
}

export default {
  state,
  getters,
  mutations,
  actions,
  namespaced: true
}